package com.kanas.webak.organization.domain;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import com.kanas.framework.support.AbstractModel;
import com.kanas.framework.util.StringUtils;
import com.kanas.webak.rbac.domain.AppUserRole;

@Entity(name="KanasWebakOrganization")
@Table(name = "kanas_organization")
@JsonIgnoreProperties({"userRoles","calendar"})
public class Organization extends AbstractModel { 

	@Transient
	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(name="id", length=32)
	private String id;
	@Column(name="code", length=100)
	private String code;
	@Column(name="label", length=100)
	private String label;
	@Column(name="active_flag")
	private Boolean activeFlag;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="parent_id",referencedColumnName="id")
	private Organization parent;
	@OneToMany(mappedBy = "parent", cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH}, fetch = FetchType.LAZY)
	private Set<Organization> childrens;
	
	@Transient
	private String oldId;

	@OneToMany(mappedBy = "organization", cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
	private Set<AppUserRole> userRoles;
	
	@OneToMany(mappedBy = "organization", cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
	private Set<Calendar> calendar;
	
	public Organization() {
		this.id = StringUtils.generateUUID();
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Override
	public String toIdString() {
		return id;
	}

	public Set<AppUserRole> getUserRoles() {
		return userRoles;
	}

	public void setUserRoles(Set<AppUserRole> roles) {
		this.userRoles = roles;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public Boolean getActiveFlag() {
		return activeFlag;
	}

	public void setActiveFlag(Boolean activeFlag) {
		this.activeFlag = activeFlag;
	}

	public String getOldId() {
		return oldId;
	}

	public void setOldId(String oldId) {
		this.oldId = oldId;
	}
	
	public Organization getParent() {
		return parent;
	}

	public void setParent(Organization parent) {
		this.parent = parent;
	}

	public Set<Organization> getChildrens() {
		return childrens;
	}

	public void setChildrens(Set<Organization> childrens) {
		this.childrens = childrens;
	}

	public Set<Calendar> getCalendar() {
		return calendar;
	}

	public void setCalendar(Set<Calendar> calendar) {
		this.calendar = calendar;
	}

}